package com.isman.placeslist.fb;


import android.app.Activity;
import android.os.Bundle;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import com.isman.placeslist.setting.ProjectPref;

public class FacebookClient {
	public static final String APP_ID = "163088263799556";
	public static final String[] PERMISSIONS = new String[]{"user_photos,publish_checkins,publish_actions,publish_stream"}; 

	private Facebook mFacebook;
	private Activity mActivity;
	
	public FacebookClient(Activity mActivity) {
		this.mActivity = mActivity;
		mFacebook = new Facebook(APP_ID);
	}
	
	public Facebook getFacebook(){
		ProjectPref.restoreFbSession(mFacebook, mActivity);
		return mFacebook;
	}
	
	public void mLogin(){
		mFacebook.authorize(mActivity, PERMISSIONS, new LoginCallback());
	}
	public void mDetail(RequestListener listener){
		ProjectPref.restoreFbSession(mFacebook, mActivity);
		AsyncFacebookRunner runner = new AsyncFacebookRunner(mFacebook);
		runner.request("/me", listener);
	}
	protected class LoginCallback implements DialogListener{
		@Override
		public void onComplete(Bundle values) {
			ProjectPref.saveFbSession(mFacebook,mActivity);
		}
		@Override
		public void onFacebookError(FacebookError e) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onError(DialogError e) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onCancel() {
			// TODO Auto-generated method stub
		}	
	}
}
